<template>
  <div class="login-container flx-center">
    <div class="login-box">
      <div class="login-left">
        <img
          class="login-left-img"
          src="@/assets/images/login_left.png"
          alt="login"
        />
      </div>
      <div class="login-form">
        <div class="login-logo">
          <img class="login-icon" src="@/assets/images/logo.svg" alt="" />
          <h2 class="logo-text">Admin</h2>
        </div>
        <WForm ref="formRef" :columns="columns" :data="data" />
        <div class="login-btn">
          <WButton round size="large" @click="onReset" prefixIco="icon-cuowu"
            >重置</WButton
          >
          <WButton
            round
            size="large"
            type="primary"
            prefixIco="icon-zhifeiji"
            @click="onLoad"
            >登录</WButton
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { WForm, WButton } from "@/components/";
import type { FormType } from "@/components/";
import { HOME_URL } from "@/config/";

// const formRef = useCompRef(WForm);

const formRef = ref<FormType.FomrInstance>();
const data = reactive({ account: "", password: "" });
const $router = useRouter();

const columns: ColumnsProps[] = [
  {
    label: "账号",
    prop: "account",
    formItem: {
      type: "input",
      input: {
        prefix: "icon-shouye",
        placeholder: "用记名：admin",
      },
    },
  },
  {
    label: "密码",
    prop: "password",
    formItem: {
      type: "input",
      input: {
        type: "password",
        showPassword: true,
        prefix: "icon-odbc-full",
        placeholder: "密码：123456",
      },
    },
  },
];

const onReset = () => {
  formRef.value?.onReset();
};

const onLoad = () => {
  formRef.value?.onSubmit();
  sessionStorage.setItem("token", "true");
  $router.replace(HOME_URL);
};
</script>

<style scoped lang="less">
@import url("./index.less");
</style>
